package com.xiyue.leaspring.service.impl;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import com.xiyue.leaspring.service.IMessageService;

@Component
public class MessageServiceImpl implements IMessageService {

	@Autowired
	private JmsTemplate jmsTemplate;//Spring提供的JMS消息操作模板
	
	@Autowired
	private Destination destination;//消息发送的目的地
	
	@Override
	public void send(String msg) {
		// TODO Auto-generated method stub
		this.jmsTemplate.send(this.destination,new MessageCreator() {
			
			@Override
			public Message createMessage(Session session) throws JMSException {
				// TODO Auto-generated method stub
				return session.createTextMessage(msg);//发送文本消息
			}
		});
	}

}
